package com.cyd.product_service.service.impl;

import com.cyd.product_service.domain.Product;
import com.cyd.product_service.service.ProductService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class ProductServiceImpl implements ProductService {

    private static final Logger log = LoggerFactory.getLogger(ProductServiceImpl.class);

    private  static Map<Integer,Product> doMap=new HashMap();

    static{
        Product p1=new Product(1,"手机",8888,100);
        Product p2=new Product(2,"电视",7894,200);
        Product p3=new Product(3,"冰箱",5864,300);
        Product p4=new Product(4,"洗衣机",4567,400);
        Product p5=new Product(5,"扫地机器人",2000,500);
        doMap.put(p1.getId(),p1);
        doMap.put(p2.getId(),p2);
        doMap.put(p3.getId(),p3);
        doMap.put(p4.getId(),p4);
        doMap.put(p5.getId(),p5);
    }

    @Override
    public List<Product> productList() {
        Collection<Product> collection=doMap.values();
        List<Product> list=new ArrayList<>(collection);
        return list;
    }

    @Override
    public Product findById(int id) {
        log.info(" service findById ......");
        return doMap.get(id);
    }
}
